package egs;

/*  Program to input 3 employee details- ID , Name ,Salary from Keyboard 
and sort the employee details by the ID and print the Max. salary */


import java.util.Scanner;


class Employee{
int id;
String name;
double sal;


public Employee(int id,String name,double sal){
this.id=id;
this.name=name;
this.sal=sal;

}

public static double printInfo(Employee[] emp){
double maxSal= emp[0].sal;
   for(int i=0;i<emp.length;i++){
      if(emp[i].sal>maxSal)
    { maxSal=emp[i].sal;}
    }
	 return maxSal;
}
   



public static Employee[] sort(Employee[] emp){
     
int n=emp.length;
Employee temp=null; 

for(int i=0;i<n;i++){

  for(int j=1;j<(n-i);j++){

    if(emp[j-1].id>emp[j].id)
        {
          temp=emp[j-1];
          emp[j-1]=emp[j];
          emp[j]=temp;
          }
          }
          }
return emp;
}


public static void printEmp(Employee[] emp){

System.out.println("\n \tID\tName\tSalary\n");
System.out.println(".......................................................");
  for(int i=0;i<emp.length;i++)
{
   
   System.out.println("\t"+emp[i].id+ "\t" +emp[i].name+"\t"+emp[i].sal);
  }
}

}

public class empSort
{
public static void main(String[] args){

Scanner in=new Scanner(System.in);
Employee[] emp=new Employee[2];  
int id=0;
double sal=0.0;
String name=null;
System.out.println("\nEnter 4 Employee id and names \n\n");

for(int i=0;i<2;i++){

System.out.print("\nID of Employee "+ (i+1) +":" );
id=in.nextInt();

System.out.print("\nName of Employee "+(i+1)+":" );
name=in.next();

System.out.print("\nSalary of Employee "+ (i+1) +":" );
sal=in.nextFloat();

 emp[i]=new Employee(id,name,sal);

}


 System.out.println("\n----- List Of Employeee Before SORT ------ \n");

  Employee.printEmp(emp);
  Employee[] sort=Employee.sort(emp);
 System.out.println( "\n\n----- List Of Employeee After SORT ------ \n");
  Employee.printEmp(sort);


//System.out.print(" Enter Employee Id to get all details  : " );

double m=Employee.printInfo(emp);
System.out.print("max :" +m);


  }
  }
  